<html>
 <?php include_once("core/header.php"); ?>

 <body>

<?php

include_once("core/database.php");

global $query_page_size;

$search = "";
$people = "";
$page = 0;

if(is_numeric($_GET["page"]))
 $page = $_GET["page"];

db_find_person_type_add($_GET["sex"]);
db_find_person_type_add($_GET["price"]);
db_find_person_type_add($_GET["place"]);

if(!empty($_GET["search"]))
{
 db_find_person_type_searchstring($_GET["search"]);
 $people = db_find_person_type($page);
 $search = htmlentities($_GET["search"],ENT_QUOTES);
}
else
{
 //do not need test, just add
 //db_find_person_type_add($_GET["value"])


 if(db_find_person_query_exists())
 {
  $people = db_find_person_type($page);
  $search = db_get_query_find_person_type();
 }
 else
 {
  $people = db_find_person_type_all($page);
 }
 
}

$link_previous = 'index.php?search='.$search.'&page='.($page-1);
$link_next =  'index.php?search='.$search.'&page='.($page+1);
//print_r($people);

?>

<div id="header" align="center">
 <div id="header-container">
  <img id="logo" src="image/logo.png" />
  <div id="menu">
   <?php include_once("view/view_form_search.php"); ?>
  </div>
  <a href="register.php"><img id="register" src="image/register.png"/></a>
 </div>
</div>

<div id="content" align="center">
 <div id="content-container">
  <?php foreach($people as $person): ?>
   <div class="content-item"align="center">
   <a href="user.php?id=<?=$person['id']?>">
    <img src="fotos/<?=$person['image1']?>" width="200" height="250"/><br>
    <div>
     <?=$person["name"]?> | <?=$person["type"]?><br/>
    </div>
   </a>
   </div>
  <?php endforeach; ?>
 </div>
</div>

<center>
<div id="link-page" align="center">
 <div id="link-previous">
 <?php if($page > 0): ?>
  <a href="<?= $link_previous ?>"><< anterior</a>
 <?php else: ?>
  <font color="gray"><< anterior</font>
 <?php endif; ?>
 </div>
 <div id="link-next">
 <?php if(sizeof($people) >= $query_page_size): ?>
  <a href="<?= $link_next ?>">próximo >></a>
 <?php else: ?>
  <font color="gray">próximo >></font>
 <?php endif; ?>
 </div>
</div>
</center>
<br>
<br>
<br>
 </body>
</html>
